﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Visa.Common.MvcContronller;
using VisaApp.Models;
using Visa.Service;
using Visa.DB;
namespace VisaApp.Controllers
{
    public class HomeController : UTController
    {
        private VisaService visaSV = new VisaService();
        private QuocGiaService QuocGiaSv = new QuocGiaService();
        private ThongtinhuuService ThongtinhuuichSv = new ThongtinhuuService();
        private TopicService TopicSv = new TopicService();
        private QuangcaoService QuangcaoSv = new QuangcaoService();
        private MenuService MenuServices = new MenuService();

        //
        // GET: /Home/

        public ActionResult Index()
        {
            TopicModel model = new TopicModel();
            try
            {
                var c = TopicSv.GetTopicBtCode("PH");
                TopicModel.MapFrom(c, ref model);
            }
            catch { }

            return View(model);

        }

        public ActionResult Menu()
        {
            var listEntity = MenuServices.GetAllMenu();
            List<MenuTinModel> model = new List<MenuTinModel>();
            try
            {
                foreach (var item in listEntity)
                {
                    MenuTinModel ml = new MenuTinModel();
                    MenuTinModel.MapFrom(item, ref  ml);
                    model.Add(ml);
                }
            }
            catch { }

            return PartialView("_Menu", model);
        }

        public ActionResult Footer()
        {
            TopicModel model = new TopicModel();
            try
            {
                var c = TopicSv.GetTopicBtCode("DC");
                TopicModel.MapFrom(c, ref model);
            }
            catch { }

            return PartialView("_Footer",model);
        }

        public ActionResult _finduS()
        {
            return PartialView();
        }

        public ActionResult Tuvanvisa()
        {
            ChauLucModel model = new ChauLucModel();
            var c = QuocGiaSv.GetChauLucByCode("142");
            ChauLucModel.MapFrom(c, ref model);
            model.listQG = new List<QuocGiaModel>();
            var cQg = QuocGiaSv.GetListQuocGia("142");

            foreach (var item in cQg)
            {
                QuocGiaModel ml = new QuocGiaModel();
                QuocGiaModel.MapFrom(item, ref ml);
                model.listQG.Add(ml);
            }

            return View(model);
        }

        public ActionResult Gioithieu()
        {
            TopicModel model = new TopicModel();
            try
            {
                var c = TopicSv.GetTopicBtCode("GT");
                TopicModel.MapFrom(c, ref model);
            }
            catch { }
            return View(model);
        }

        public ActionResult Thongtinhuuich()
        {
            TopicModel model = new TopicModel();
            try
            {
                var c = TopicSv.GetTopicBtCode("TTHI");
                TopicModel.MapFrom(c, ref model);
            }
            catch { }
            return View(model);
        }

        public ActionResult Cauhoithuonggap()
        {
            TopicModel model = new TopicModel();
             try
            {
            var c = TopicSv.GetTopicBtCode("CHTG");
            TopicModel.MapFrom(c, ref model);
                 }
            catch { }
            return View(model);
        }

        public ActionResult Tintuc()
        {
            TopicModel model = new TopicModel();
             try
            {
            var c = TopicSv.GetTopicBtCode("TT");
            TopicModel.MapFrom(c, ref model);
                 }
            catch { }
            return View(model);
        }

        public ActionResult Ykienkhachang()
        {
            TopicModel model = new TopicModel();
             try
            {
            var c = TopicSv.GetTopicBtCode("YKKH");
            TopicModel.MapFrom(c, ref model);
                 }
            catch { }
            return View(model);
        }

        public ActionResult Thuvien()
        {
            TopicModel model = new TopicModel();
             try
            {
            var c = TopicSv.GetTopicBtCode("TV");
            TopicModel.MapFrom(c, ref model);
            }
             catch { }
            return View(model);
        }

        public ActionResult TuyenDung()
        {
            return View();
        }

        public ActionResult Quancao()
        {
            TopicModel model = new TopicModel();
            try
            {
                var c = TopicSv.GetTopicBtCode("QC");
                TopicModel.MapFrom(c, ref model);
            }
            catch { }
            return View(model);
        }

        public ActionResult Ads(string Postion)
        {
            var c = QuangcaoSv.GetNewsByPostion(Postion);
            List<QuangcaoModel> model = new List<QuangcaoModel>();
            if (c != null)
            {
                c.ForEach(delegate(Quangcao tt)
                {
                    QuangcaoModel ml = new QuangcaoModel()
                    {
                        Mota = tt.Mota,
                        Id = tt.Id,
                        Postition = tt.Postition,
                        Datecreate = tt.Datecreate,
                        DateEnd = tt.DateEnd,
                        FileUrl = tt.FileUrl,
                        Type = tt.Type,
                        Url = tt.Url,
                    };
                    model.Add(ml);
                });
            }

            return PartialView("_Ads", model);

        }

        public ActionResult menuDetails(int Id, string name)
        {
            MenuTinModel model = new MenuTinModel();
            var entity = MenuServices.GetMenuById(Id);
            try
            {
                MenuTinModel.MapFrom(entity, ref model);
            }
            catch { }

            return View("menuDetails", model);
        }

    }
}
